<?php
/**
* @version $Id: submit.php,v 1.0 2005/10/02 13:15:15 mic Exp $
* @package XfaQ - a frequently asked question component for Joomla! & Mambo CMS
* @copyright (C) 2005 mgfi.info
* @info info@mgfi.info http://www.mgfi.info
* @license GNU/GPL
* based in simplefaq 2.0.1 & glossary 1.4
*/

defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

class HTML_xfaq {

    function showxFAQEntries( $option, &$rows, &$search, &$pageNav, &$lists ) {
		global $my; ?>
		<form action="index2.php" method="post" name="adminForm">
		    <table class="adminheading">
            	<tr>
                    <th><?php echo _XFAQ_MANAGER; ?></th>
                    <td><?php echo _XFAQ_FILTER; ?>:</td>
                    <td>
                    	<input type="text" name="search" value="<?php echo $search;?>" class="inputbox" onChange="document.adminForm.submit();" />
                    </td>
                    <td width="right">
                    <?php echo $lists['catid'];?>
                    </td>
            	</tr>
            </table>

		    <table class="adminlist">
                <tr>
                    <th width="20" nowrap="nowrap">#</th>
                    <th width="20" class="title" nowrap="true">
                        <input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($rows); ?>);" />
                    </th>
                    <th width="40%" class="title" nowrap="true"><?php echo _XFAQ_QUESTION; ?></th>
                    <th width="50" class="title" nowrap="true"><?php echo _XFAQ_PUBLISHED; ?></th>
                    <th colspan="2" nowrap="nowrap"><?php echo _XFAQ_REORDER; ?></th>
                    <th width="2%"><?php echo _XFAQ_ORDER; ?></th>
                    <th width="1%">
                        <a href="javascript: saveorder( <?php echo count( $rows )-1; ?> )"><img src="images/filesave.png" border="0" width="16" height="16" alt="<?php echo _XFAQ_SAVE_ORDER; ?>" title="<?php echo _XFAQ_SAVE_ORDER; ?>" /></a>
                    </th>
                    <th nowrap="true" width="20%" align="left"><?php echo _XFAQ_CATEGORY; ?></th>
                    <th nowrap="true" align="center"><?php echo _XFAQ_DATE; ?></th>
                    <th class="title" nowrap="true" width="10%"><?php echo _XFAQ_CHECKED_OUT; ?></th>
                </tr>
                <?php
                $k = 0;
                for ($i=0, $n=count($rows); $i < $n; $i++) {
                    $row = $rows[$i];
                    $img = $row->published ? 'tick.png' : 'publish_x.png';
                    $task = $row->published ? 'unpublish' : 'publish';
                    $alt = $row->published ? _XFAQ_PUBLISHED_CLICK_TO_UNDO : _XFAQ_UNPUBLISHED_CLICK_TO_PUB;
                    $title = $row->published ? _XFAQ_PUBLISHED_CLICK_TO_UNDO : _XFAQ_UNPUBLISHED_CLICK_TO_PUB;
                    ?>
                    <tr class="<?php echo "row$k"; ?>">
                        <td width="20">
                        <?php echo $pageNav->rowNumber( $i ); ?>
                        </td>
                        <td width="20">
                        <?php echo mosHTML::idBox( $i, $row->id, ($row->checked_out && $row->checked_out != $my->id ) ); ?>
                        </td>
                        <td width="20%">
                        <?php
                        if ( $row->checked_out && ( $row->checked_out != $my->id ) ) {
                            ?>
                            <?php echo $row->question; ?>
                            &nbsp;[ <i><?php echo _XFAQ_CHECKED_OUT; ?></i> ]
                            <?php
                        } else {
                            ?>
                            <a href="#edit" onclick="return listItemTask('cb<?php echo $i;?>','edit')">
                            <?php echo htmlspecialchars( $row->question, ENT_QUOTES ); ?>
                            </a>
                            <?php
                        }
                        ?>
                        </td>
                        <td width="10%" align="center">
                        	<a href="javascript: void(0);" onClick="return listItemTask('cb<?php echo $i;?>','<?php echo $task;?>')">
                        	<img src="images/<?php echo $img;?>" width="12" height="12" border="0" alt="<?php echo $alt; ?>" title="<?php echo $title; ?>" />
                        	</a>
                        </td>
                        <td><?php echo $pageNav->orderUpIcon( $i ); ?></td>
                        <td><?php echo $pageNav->orderDownIcon( $i, $n ); ?></td>
                        <td align="center" colspan="2">
                        	<input type="text" name="order[]" size="5" value="<?php echo $row->ordering; ?>" class="text_area" style="text-align: center" />
                        </td>
                        <td align="left"><?php echo $row->category; ?></td>
                        <td align="center" nowrap="true"><?php echo $row->date_created; ?></td>
                        <td><?php echo $row->checked_out ? $row->editor : ''; ?></td>
                    </tr>
                    <?php
                    $k = 1 - $k;
                }
                ?>
            </table>
            <?php echo $pageNav->getListFooter(); ?>

            <input type="hidden" name="option" value="<?php echo $option; ?>" />
            <input type="hidden" name="task" value="" />
            <input type="hidden" name="boxchecked" value="0" />
		</form>
		<?php
	}

    function editxFAQ( $option, &$row, &$publist, &$clist ) {
        require( $GLOBALS['mosConfig_absolute_path'] . '/administrator/components/com_xfaq/config.xfaq.php' ); ?>
        <script type="text/javascript">
            <!--
            function submitbutton(pressbutton) {
              var form = document.adminForm;
              <?php getEditorContents( 'editor1', 'answer' ) ;?>
              if (pressbutton == 'cancel') {
                submitform( pressbutton );
                return;
              }
              // do field validation
              if (form.question.value == ""){
                alert( "Entry must have a Question." );
              } else if (form.catid.value == "0"){
            alert( "<?php echo _XFAQ_SELECT_FIRST_CATEGORY; ?>" );
              } else {
                submitform( pressbutton );
              }
            }
            //-->
        </script>

        <form action="index2.php" method="post" name="adminForm" id="adminForm">
            <table cellpadding="4" cellspacing="1" border="0" width="100%" class="adminform">
                <tr>
                    <th colspan="2" class="title" >
                        <?php echo $row->id ? _XFAQ_EDIT : _XFAQ_ADD;?>&nbsp;<?php echo _XFAQ_XFAQ . ' ' . _XFAQ_ENTRY; ?>
                    </th>
                </tr>
                <tr>
                    <td valign="top" align="right"><?php echo _XFAQ_QUESTION; ?>:</td>
                    <td>
                        <textarea cols="50" rows="3" name="question" class="inputbox" wrap="virtual"><?php echo $row->question; ?></textarea>
                    </td>
                </tr>
                <tr>
                    <td valign="top" align="right"><?php echo _XFAQ_ANSWER; ?>:</td>
                    <td width="420" valign="top">
                        <textarea cols="50" rows="8" name="answer" class="inputbox" wrap="virtual"><?php echo $row->answer ; ?></textarea>
                        <?php
                        //editorArea( 'editor1',  $row->answer, 'answer', '500', '200', '70', '30' ) ;
                        ?>
                    </td>
                </tr>
                <tr>
                    <td valign="top" align="right"><?php echo _XFAQ_CATEGORY; ?>:</td>
                    <td><?php echo $clist; ?></td>
                </tr>

                <tr>
                    <td width="20%" align="right"><?php echo _XFAQ_NAME; ?>:</td>
                    <td width="80%">
                        <input class="inputbox" type="text" name="name" size="50" maxlength="100" value="<?php echo htmlspecialchars( $row->name, ENT_QUOTES );?>" />
                    </td>
                </tr>
                <tr>
                    <td valign="top" align="right"><?php echo _XFAQ_EMAIL; ?>:</td>
                    <td>
                        <input class="inputbox" type="text" name="email" value="<?php echo $row->email; ?>" size="50" maxlength="100" />
                    </td>
                </tr>
                <tr>
                    <td valign="top" align="right"><?php echo _XFAQ_HOMEPAGE; ?>:</td>
                    <td>
                        <input class="inputbox" type="text" name="homepage" value="<?php echo $row->homepage; ?>" size="50" maxlength="100" />
                    </td>
                </tr>
                <tr>
                    <td valign="top" align="right"><?php echo _XFAQ_COMMENT; ?>:</td>
                    <td>
                        <textarea class="inputbox" cols="50" rows="3" name="comment" style="width=500px" width="500"><?php echo htmlspecialchars( $row->comment, ENT_QUOTES );?></textarea>
                    </td>
                </tr>
                <tr>
                    <td valign="top" align="right"><?php echo _XFAQ_PUBLISHED; ?>:</td>
                    <td><?php echo $publist; ?></td>
                </tr>

            </table>

            <input type="hidden" name="date_created" value="<?php echo time(); ?>" />
            <input type="hidden" name="id" value="<?php echo $row->id; ?>" />
            <input type="hidden" name="option" value="<?php echo $option;?>" />
            <input type="hidden" name="task" value="" />
        </form>
        <?php
    } // end editxfaq
} // End of class
?>